# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause

if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
    cmake_minimum_required(VERSION 3.16)
    project(tst_qmlsplitlib LANGUAGES CXX)
    find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()

include(GenerateExportHeader)

qt_add_library(tst_qmlsplitlib_library
        lib.h
        lib.cpp
)
qt_autogen_tools_initial_setup(tst_qmlsplitlib_library)
target_include_directories(tst_qmlsplitlib_library PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # find autogenerated header
generate_export_header(tst_qmlsplitlib_library)

target_link_libraries(tst_qmlsplitlib_library Qt::Core Qt::QmlIntegration)

qt_add_library(tst-qmlsplitlib-library-2
        lib2.h
        lib2.cpp
)
qt_autogen_tools_initial_setup(tst-qmlsplitlib-library-2)
target_include_directories(tst-qmlsplitlib-library-2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # find autogenerated header
generate_export_header(tst-qmlsplitlib-library-2)

target_link_libraries(tst-qmlsplitlib-library-2 Qt::Core Qt::QmlIntegration)


qt_internal_add_test(tst_qmlsplitlib
    SOURCES
        tst_qmlsplitlib.cpp
    LIBRARIES
        Qt::Core
        Qt::Qml
)
qt_autogen_tools_initial_setup(tst_qmlsplitlib)

qt6_generate_foreign_qml_types(tst_qmlsplitlib_library tst_qmlsplitlib)
qt6_generate_foreign_qml_types(tst-qmlsplitlib-library-2 tst_qmlsplitlib)

qt_policy(SET QTP0001 NEW)

qt6_add_qml_module(tst_qmlsplitlib
    URI "SplitLib"
    QML_FILES
        main.qml
        main2.qml
)

target_link_libraries(tst_qmlsplitlib PRIVATE tst_qmlsplitlib_library tst-qmlsplitlib-library-2)
